
//
//  WUEditViewController.m
//  Home
//
//  Created by 吴军虎吴军虎 on 16/5/7.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "WUEditViewController.h"
#import "YHYEditHomePageViewController.h"
#import "CaseDetail.h"

@interface WUEditViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UIView *footerView;
    
    UITableView *mytableView;
}

@property (nonatomic,retain)UIButton *button;

@property (nonatomic,strong)UIButton *removeBotton;


@end

@implementation WUEditViewController

- (void)viewWillAppear:(BOOL)animated {
    
    self.title = @"案例详情";
    self.tabBarController.tabBar.hidden=YES;
    
    self.navigationController.navigationBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = NO;
    
}

-(void) viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.translucent = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self getAFNetWorking];
    [self creatView];
    
}


- (void)creatView{
    
    
    //    左侧的图标
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(Back:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.view.backgroundColor = LV;
    
    mytableView = [[UITableView alloc]initWithFrame:CGRectMake(0, -25 * AUTO_HEIGHT, KScreenWidth, KScreenHeight) style:UITableViewStyleGrouped];
    mytableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    mytableView.backgroundColor = LV;
    [self.view addSubview:mytableView];
    mytableView.delegate = self;
    mytableView.dataSource = self;
    
    footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenHeight, 200*AUTO_HEIGHT)];
    mytableView.tableFooterView = footerView;
    
    //
    //
    //
    //下一步
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.backgroundColor = GH;
    [footerView addSubview:_button];
    self.button.layer.masksToBounds = YES;
    self.button.layer.cornerRadius = 5;
    [self.button setTitle:@"编 辑" forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(goNext:) forControlEvents:UIControlEventTouchUpInside];
    [self.button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(footerView.mas_top).offset(44 * AUTO_HEIGHT);
        make.centerXWithinMargins.mas_equalTo(self.view);
        make.height.mas_equalTo(78/2 * AUTO_HEIGHT);
        make.width.mas_equalTo(SCREEN_WIDTH - 88/2 * AUTO_WIDTH);
    }];
    self.button.titleLabel.font = [UIFont fontWithName:@"Arial" size:LOGINFONT * TEXTWEIGHT];
    
    
    
    _removeBotton = [UIButton new];
    [footerView addSubview:_removeBotton];
    self.removeBotton.backgroundColor = [UIColor colorWithRed:248/255.0 green:84/255.0 blue:85/255.0 alpha:1];
    self.removeBotton.layer.masksToBounds = YES;
    self.removeBotton.layer.cornerRadius = 5;
    [self.removeBotton setTitle:@"删 除" forState:UIControlStateNormal];
    [self.removeBotton addTarget:self action:@selector(removeBotton:) forControlEvents:UIControlEventTouchUpInside];
    [self.removeBotton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.removeBotton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_button.mas_bottom).offset(30 * AUTO_HEIGHT);
        make.centerXWithinMargins.mas_equalTo(self.view);
        make.height.mas_equalTo(78/2 * AUTO_HEIGHT);
        make.width.mas_equalTo(SCREEN_WIDTH - 88/2 * AUTO_WIDTH);
    }];
    self.removeBotton.titleLabel.font = [UIFont fontWithName:@"Arial" size:LOGINFONT * TEXTWEIGHT];
    //
    //
    //
}



-(NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 360 *AUTO_HEIGHT;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSString *identifer = [NSString stringWithFormat:@"%ld%ld",indexPath.section,indexPath.row];
    CaseDetail *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
    if (!cell) {
        cell = [[CaseDetail alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    cell.backgroundColor = LV;
    [cell settingModel:self.model];
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    
}



// 编辑
- (void)goNext:(UIButton *)btu{
    
    YHYEditHomePageViewController *edit=[[YHYEditHomePageViewController alloc]init];
    edit.navigationController.navigationItem.title = @"修改案例";
    edit.myID = self.model.markID;
    edit.model = self.model;
    [self.navigationController pushViewController:edit animated:YES];
    
}
- (void)removeBotton:(UIButton *)btu{
    
    NSString *url_string = [NSString stringWithFormat:@"%@%@",JIAFANURL,@"Gafaer/Case/delCase"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = HTTPSET;
    [manager GET:url_string parameters:@{@"uid":[LOCALSEVE objectForKey:@"UID"],@"mcode":[LOCALSEVE objectForKey:@"MCODE"],@"tid":self.myID} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"案例删除%@",responseObject);
        if ([[responseObject objectForKey:@"code"] isEqualToString:@"200"]) {
            
        }
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"error%@",error);
        
        
    }];
    
    
    
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)getAFNetWorking{
    
    NSString *url_string = [NSString stringWithFormat:@"%@%@",JIAFANURL,@"Gafaer/Case/viewCase"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = HTTPSET;
    [manager GET:url_string parameters:@{@"uid":[LOCALSEVE objectForKey:@"UID"],@"mcode":[LOCALSEVE objectForKey:@"MCODE"],@"tid":self.myID} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"案例详情%@",responseObject);
        self.model = [ResignModel new];
        [self.model setValuesForKeysWithDictionary:[responseObject objectForKey:@"data"]];
        
        
        [mytableView reloadData];
        //
        //        [manager POST:url_string parameters:@{@"uid":[LOCALSEVE objectForKey:@"UID"],@"mcode":[LOCALSEVE objectForKey:@"MCODE"],@"tid":self.myID} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //
        //
        //        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //
        //
        //
        //
        //
        //
        //
        //        }];
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"error%@",error);
        
        
    }];
    
    
    
    
    
}
-(void)Back:(UIBarButtonItem *)back{
    
    [self.navigationController popViewControllerAnimated:YES];
}


@end
